package com.qfmy.web.app.controller.novel;

import com.qfmy.common.result.Result;
import com.qfmy.model.entity.novel.NovelComment;
import com.qfmy.model.vo.novel.NovelCommentVo;
import com.qfmy.web.app.service.novel.NovelCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.web.app.controller.novel
 * @date 2025/10/31
 * @description 小说评论表
 */
@RestController
@RequestMapping("/app/novelComment")
public class NovelCommentController {

    /**
     * 注入service
     */
    @Autowired
    private NovelCommentService novelCommentService;

    /**
     * 根据小说id获取评论列表
     */
    @RequestMapping("/getCommentsByNovelId")
    public Result<List<NovelCommentVo>> getCommentsByNovelId(@RequestParam Integer novelId) {
        List<NovelCommentVo> list = novelCommentService.getCommentsByNovelId(novelId);
        return Result.ok(list);
    }

    /**
     * 添加评论
     */
    @RequestMapping("/addComment")
    public Result<String> addComment(@RequestBody NovelComment novelComment) {
        novelCommentService.addComment(novelComment);
        return Result.ok();
    }

    /**
     * 判断当前用户是否已经评价过
     */
    @RequestMapping("/isComment")
    public Result<Boolean> isComment(@RequestParam Integer novelId) {
        return Result.ok(novelCommentService.isComment(novelId));
    }


}
